<?php
namespace app\common\model;

use think\Model;

class Deal extends BaseModel
{

	public function getNormalDeals($data = []) {
        $data['status'] = 1;
        $order = ['id'=>'desc'];
        $list = $this->where($data)->order($order)->paginate();

        return $list;
	}

	public function getApplyDeals($data = []) {
		$data['status'] = 0;
		$order = ['id'=>'desc'];

		$result = $this->where($data)
			->order($order)
			->paginate();

		//echo $this->getLastSql();
		return  $result;
	}

	/**
	 * 根据分类 以及 城市来获取 商品数据
	 * @param $id 分类
	 * @param $cityId 城市
	 * @param int $limit 条数
	 */
	public function getNormalDealByCategoryCityId($id, $cityId, $limit=10) {
		$data  = [
			'end_time' => ['gt', time()],
			'category_id' => $id,
			'city_id' => $cityId,
			'status' => 1,
		];

		$order = [
			'listorder'=>'desc',
			'id'=>'desc',
		];

		$result = $this->where($data)
			->order($order);
		if($limit) {
			$result = $result->limit($limit);
		}
		return $result->select();
	}

	public function getDealByConditions($data=[],$orders){
        if(!empty($orders['order_sales'])){
            $order['buy_count'] = 'desc';
        }
        if(!empty($orders['order_price'])){
            $order['current_price'] = 'desc';
        }
        if(!empty($orders['order_time'])){
            $order['create_time'] = 'desc';
        }
        $order['id'] = 'desc';

        $result = $this->where($data)
            ->order($order)
            ->paginate();
        return $result;
	}


}